package com.dong.thread.threadbasic;

/**
 * 上锁的本质
 * 上锁的本质是把并发编程序列化
 *
 * @author by jiweidong on 2021/11/26.
 */
public class T18_Atomicity_WhatIsLock {

    private static Object o = new Object();

    public static void main(String[] args) {
        Runnable r = () -> {
            //synchronized (o) { //打开注释试试看，对比结果
            System.out.println(Thread.currentThread().getName() + " start!");
            SleepHelper.sleepSeconds(2);
            System.out.println(Thread.currentThread().getName() + " end!");
            //}
        };

        for (int i = 0; i < 3; i++) {
            new Thread(r).start();
        }
    }
}
